# -*- coding:utf-8 -*-
# ==========================================
#       Author: ZiChen
#        Mail: 1538185121@qq.com
#         Time: 2021/06/06
#           Version: 0.3
#             Description: MP3编辑
# ==========================================
import MP3Edit
import configparser
version = '0.3'  # 主程序版本
#  实例化configParser对象
config = configparser.ConfigParser()

print("欢迎使用音乐信息编辑器{mainVer}！\n\
=====已导入插件=====\n\
{Name01} - Version:{Ver01}".format(
    mainVer=version,
    Name01=MP3Edit.name, Ver01=MP3Edit.version,
))

# 读取配置文件
configPath = input("请输入配置文件路径:\n")
config.read(configPath, encoding='utf-8')
imgPath = config.get('data', 'imgPath')
artist = config.get('data', 'artist')
album = config.get('data', 'album')
while True:
    model = input("1.单曲模式\n2.批量模式\n")
    # 单曲
    if model == '1':
        path = input("请输入需要修改的歌曲(mp3)路径:\n")
        title = input("请输入歌曲标题：\n")
        with open(imgPath, 'rb') as f:
            picData = f.read()
        info = {'picData': picData, 'title': title,
                'artist': artist, 'album': album}
        MP3Edit.edit(path, info)
        print("Finish√\n")
    # 批量
    elif model == '2':
        songFilePath = input("批量操作文件路径：\n")
        with open(songFilePath, 'r', encoding='utf-8') as f:
            pathlst = f.read().split('\n')
            print(pathlst)
        for i in pathlst:
            # 排除mp3文件以外的歌曲文件
            if i.split('.')[-1] != 'mp3':
                continue
            else:
                print('===\n歌曲：%s\n===' % i.split('\\')[-1])
                title = input("请输入歌曲标题：\n")
                # 不导入封面图
                if imgPath == 'None':
                    picdata = 'None'
                else:
                    with open(imgPath, 'rb') as f:
                        picData = f.read()
                info = {'picData': picData, 'title': title,
                        'artist': artist, 'album': album}
                MP3Edit.edit(i, info)
                print("Finish√\n")
